package com.jomoo.remark.action;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.jomoo.common.utils.BaseAction;
import com.jomoo.remark.service.RemarkService;

/**
 * jomoo备忘录控制层
 * 
 * @author 郝思聪
 * @date 2017年01月12日
 */
@Scope("prototype")
@Component("RemarkAction")
public class RemarkAction extends BaseAction
{
	private static final long serialVersionUID = -1828185402284378810L;

	Log log = LogFactory.getLog(RemarkAction.class);

	@Resource
	RemarkService remarkService;

	/**
	 * 录入账目
	 * @return String
	 */
	@Action(value = "addRemark")
	public void saveAccount()
	{
		String strTitle = request.getParameter("titles");
		String strContent = request.getParameter("contents");
		
		Map<String, Boolean> map = new HashMap<String, Boolean>(10);
		Integer iId = null;

		try
		{
			// 传参录入信息
			iId = remarkService.addRemark(strTitle, strContent);
			
			if(null != iId)
			{
				map.put("result", true);
			}
			else
			{
				map.put("result", false);
			}

			// 直接用fastjson解析为json字符串输出
			returnData(JSON.toJSONString(map));
		}
		catch (Exception e)
		{
			e.printStackTrace();
			log.error("录入备忘录异常：" + e.getMessage());
		}
	}
}
